package com.registration.ant;

import com.registration.core.Attendee;
import com.registration.core.Category;
import com.registration.core.Country;
import com.registration.core.MemberVerification;
import com.registration.membership.Member;
import com.registration.membership.MemberType;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 * @author Ggutierrez
 */
public class CreateBaselineDataTask extends Task {

    private Session session;
    private SimpleDateFormat dateformat = new SimpleDateFormat("MM-dd-yyyy");
    private SimpleDateFormat timestampformat = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss a");

    /**
     * Creates a new instance of CreateBaselineDataTask
     */
    public CreateBaselineDataTask() {
    }

    public static void main(String[] args) {
        System.out.println("CreateBaselineDataTask");
        Task task = new CreateBaselineDataTask();
        task.execute();
    }

    @Override
    public void execute() throws BuildException {
        Configuration cfg = new Configuration();
        cfg.configure();
        SessionFactory sf = cfg.buildSessionFactory();
        session = sf.openSession();
        Transaction tx = session.beginTransaction();
        try {
            createNationalities();
            createCategories();
//            createAttendees();
//            createMembers();

            tx.commit();
        } catch (Exception e) {
            log(e, 0);
            e.printStackTrace();
            tx.rollback();
            throw new BuildException(e);
        } finally {
            session.close();
            sf.close();
        }
    }

    public void createAttendees() throws ParseException {
        Attendee attendee = new Attendee("Giovanella", "", "Gutierrez", "88519210", "giova_gut@yahoo.com", "1234569-01", null);
        attendee.setCountry((Country) session.get(Country.class, 1L));
        attendee.setMemberVerification(MemberVerification.VERIFICADO);
        attendee.setCategory((Category) session.get(Category.class, 1L));
        session.persist(attendee);
    }

    public void createCategories() throws ParseException {
        session.persist(new Category("Profesional Miembro", 150F));
        session.persist(new Category("Estudiante Miembro", 80F));
        session.persist(new Category("Profesional No Miembro", 200F));
        session.persist(new Category("Estudiante No Miembro", 120F));
        session.persist(new Category("Personal de Stand", 0F));
        session.persist(new Category("Conferencista", 125F));
        session.persist(new Category("Acompanante", 100F));
        session.persist(new Category("Daily Pass", 100F));
        session.persist(new Category("Tutoriales", 0F));
    }

    public void createNationalities() throws ParseException {
        session.persist(new Country("Alemania", "alemán / ana", ""));
        session.persist(new Country("Argentina", "argentino / a", ""));
        session.persist(new Country("Australia", "australiano / a", ""));
        session.persist(new Country("Austria", "austríaco / a", ""));
        session.persist(new Country("Bélgica", "belga", ""));
        session.persist(new Country("Bolivia", "boliviano / a", ""));
        session.persist(new Country("Bosnia", "bosnio / a", ""));
        session.persist(new Country("Brasil", "brasileño / a", ""));
        session.persist(new Country("Bulgaria", "búlgaro / a", ""));
        session.persist(new Country("Camboya", "camboyano / a", ""));
        session.persist(new Country("Canadá", "canadiense", ""));
        session.persist(new Country("Chile", "chileno / a", ""));
        session.persist(new Country("China", "chino / a", ""));
        session.persist(new Country("Colombia", "colombiano / a", ""));
        session.persist(new Country("Corea", "coreano / a", ""));
        session.persist(new Country("Costa Rica", "costarricense", ""));
        session.persist(new Country("Croacia", "croata", ""));
        session.persist(new Country("Cuba", "cubano / a", ""));
        session.persist(new Country("Dinamarca", "danés / esa", ""));
        session.persist(new Country("Ecuador", "ecuatoriano / a", ""));
        session.persist(new Country("El Salvador", "salvadoreño / a", ""));
        session.persist(new Country("Escocia", "escocés / esa", ""));
        session.persist(new Country("Eslovaquia", "eslovaco / a", ""));
        session.persist(new Country("Eslovenia", "esloveno / a", ""));
        session.persist(new Country("España", "español / ola", ""));
        session.persist(new Country("Estados Unidos", "estadounidense", ""));
        session.persist(new Country("Filipinas", "filipino / a", ""));
        session.persist(new Country("Finlandia", "finlandés / esa", ""));
        session.persist(new Country("Francia", "francés / esa", ""));
        session.persist(new Country("Gales", "galés / esa", ""));
        session.persist(new Country("Gran Bretaña", "británico / a", ""));
        session.persist(new Country("Grecia", "griego / a", ""));
        session.persist(new Country("Guatemala", "guatemalteco / a", ""));
        session.persist(new Country("Haití", "haitiano / a", ""));
        session.persist(new Country("Holanda", "holandés / esa", ""));
        session.persist(new Country("Honduras", "hondureño / a", ""));
        session.persist(new Country("Hungría", "húngaro / a", ""));
        session.persist(new Country("India", "indio / a", ""));
        session.persist(new Country("Indonesia", "indonesio / a", ""));
        session.persist(new Country("Inglaterra", "inglés / esa", ""));
        session.persist(new Country("Irlanda", "irlandés / esa del sur", ""));
        session.persist(new Country("Irlanda del Norte", "irlandés / esa del norte", ""));
        session.persist(new Country("Italia", "italiano / a", ""));
        session.persist(new Country("Japón", "japonés /esa", ""));
        session.persist(new Country("La República Checa", "checo / a", ""));
        session.persist(new Country("Luxemburgo", "luxemburgués / esa", ""));
        session.persist(new Country("Malasia", "malayo / a", ""));
        session.persist(new Country("México", "mexicano / a", ""));
        session.persist(new Country("Nepal", "nepalí", ""));
        session.persist(new Country("Nicaragua", "nicaragüense", ""));
        session.persist(new Country("Noruega", "noruego / a", ""));
        session.persist(new Country("Nueva Zelanda", "neozelandés", ""));
        session.persist(new Country("Panamá", "panameño / a", ""));
        session.persist(new Country("Paraguay", "paraguayo / a", ""));
        session.persist(new Country("Perú", "peruano / a", ""));
        session.persist(new Country("Polonia", "polaco /a", ""));
        session.persist(new Country("Portugal", "portugués /esa", ""));
        session.persist(new Country("República Dominicana", "dominicano / a", ""));
        session.persist(new Country("Rumania", "rumano/ana", ""));
        session.persist(new Country("Rusia", "ruso / a", ""));
        session.persist(new Country("Serbia", "serbio/a", ""));
        session.persist(new Country("Singapur", "singapurense", ""));
        session.persist(new Country("Suecia", "sueco / a", ""));
        session.persist(new Country("Suiza", "suizo / a", ""));
        session.persist(new Country("Tailandia", "tailandés /esa", ""));
        session.persist(new Country("Taiwán", "taiwanés/esa", ""));
        session.persist(new Country("Turquía", "turco / a", ""));
        session.persist(new Country("Uruguay", "uruguayo / a", ""));
        session.persist(new Country("Venezuela", "venezolano / a", ""));
        session.persist(new Country("Vietnam", "vietnamita", ""));
    }

    public void createMembers() throws ParseException {
        session.persist(new Member("23456789-01", "Guilber", "J", "Castillo", "Profesional Nicaragua", null, MemberType.PROFESIONAL));
        session.persist(new Member("89745562-01", "Luis", "A", "Morales", "Profesional Nicaragua", null, MemberType.PROFESIONAL));
    }
}